#coding=utf8
import math

class L(object):
    
    def __init__(self, l):
        self.l = l
        
    def toShannonWeaver(self):
        s = sum(self.l)
        t = sum( [i*math.log10(i) for i in self.l if i > 0] )
        return 3.322/s * (s*math.log10(s) - t )
    
    def toShannonWeaver3(self):
        N = sum(self.l)*1.0
        return -sum( [i*math.log(i/N, 2) for i in self.l if i > 0] )/N
        
    def toSimpson(self):
        N = sum(self.l)*1.0
        return 1 - sum([ (i/N)**2.0 for i in self.l if i > 0])
    
